<?php

namespace App\Http\Controllers\Labaicai;

use App\Http\Requests\Labaicai\DailyDietRequest;
use App\Http\Resources\Labaicai\DailyDietResource;
use App\Models\Labaicai\DailyDiet;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class DailyDietController extends Controller
{
    public function __construct()
    {
        $this->middleware('');
    }

    /**
     * Notes:
     * Created on 2024-02-02 02:59:32
     * @param Request $request
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public function index(Request $request)
    {
        $query = DailyDiet::filter();
        return DailyDietResource::collection(
            $request->has('page') ? $query->paginate(per()) : $query->get()
        );
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(DailyDietRequest $request)
    {
        DailyDiet::create($request->all());
    }

    /**
     * Notes:
     * Created on 2024-02-02 02:59:32
     * @param $id
     * @return DailyDietResource
     */
    public function show($id)
    {
        return DailyDietResource::make(DailyDiet::findOrFail($id));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(DailyDietRequest $request, $id)
    {
        DailyDiet::where('id', $id)->updateFillable($request->all());
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $m = DailyDiet::findOrFail($id);
        $m->delete();
    }
}
